import 'package:abc/view/CustomActionCard.dart';
import 'package:abc/view/CustomInputField.dart';
import 'package:abc/view/KeyboardAwareBottomSheet.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class ProfileController extends GetxController {
  RxString nickName = '张大美丽'.obs; //昵称
  RxString signContent = '这个人很懒，什么都没有留下～'.obs;
  RxString gender = '男'.obs; // 性别，默认为男

  void showNickNameheet(BuildContext context) {
    final textController = TextEditingController();
    showModalBottomSheet<void>(
      context: context,
      shape: const RoundedRectangleBorder(
        borderRadius: BorderRadius.vertical(top: Radius.circular(20.0)),
      ),
      // 确保键盘弹出时 Bottom Sheet 能自动调整位置
      isScrollControlled: true,
      builder: (BuildContext context) {
        return KeyboardAwareBottomSheet(
          onDismiss: () => Navigator.of(context).pop(),
          child: CustomActionCard(
            onClose: () => Navigator.of(context).pop(),
            iconWidget: Image.asset(
              'assets/images/profile_change_name.png',
              width: 75,
              height: 73,
            ),
            title: '给自己一个好听的名字吧！',
            textController: textController,
            isShowTextFild: true,
            contentWidget: CustomInputField(
              hintText: nickName.value,
              controller: textController,
            ),
            footerNotes: Text(
              """温馨提示：
1、每个自然月仅能修改一次
2、紧张使用违规信息，则将被永久封禁
3、用户资料需审核，审核通过后将会展示，请耐心等待""",
              style: TextStyle(
                fontWeight: FontWeight.w400,
                fontSize: 13,
                color: Color(0xFF999999),
              ),
            ),
            primaryButtonText: '确定',
            onPrimaryButtonPressed: () {
              print('点击确定');
              nickName.value = textController.text.toString();
              Navigator.of(context).pop();
            },
          ),
        );
      },
    );
  }

  void showSignSheet(BuildContext context) {
    final textController = TextEditingController();
    showModalBottomSheet<void>(
      context: context,
      shape: const RoundedRectangleBorder(
        borderRadius: BorderRadius.vertical(top: Radius.circular(20.0)),
      ),
      // 确保键盘弹出时 Bottom Sheet 能自动调整位置
      isScrollControlled: true,
      builder: (BuildContext context) {
        return KeyboardAwareBottomSheet(
          onDismiss: () => Navigator.of(context).pop(),
          child: CustomActionCard(
            onClose: () => Navigator.of(context).pop(),
            iconWidget: Image.asset(
              'assets/images/profile_sign.png',
              width: 78,
              height: 73,
            ),
            title: '给自己写上个性签名吧！',
            textController: textController,
            isShowTextFild: true,
            contentWidget: TextField(
              controller: textController,
              textAlign: TextAlign.left, // 设置文字居中
              maxLines: 3, // 多行
              style: const TextStyle(
                fontWeight: FontWeight.bold, // 设置文字加粗
                fontSize: 15.0, // 可以根据需要调整字体大小
              ),
              // 核心样式配置
              decoration: InputDecoration(
                hintText: signContent.value,
                filled: true,
                fillColor: const Color(0xFFF5F6FA),
                contentPadding: const EdgeInsets.symmetric(
                  horizontal: 5.0,
                  vertical: 10.0,
                ),
                border: OutlineInputBorder(borderSide: BorderSide.none),
                focusedBorder: OutlineInputBorder(borderSide: BorderSide.none),
                enabledBorder: OutlineInputBorder(borderSide: BorderSide.none),
                hintStyle: TextStyle(color: Color(0XFF999999), fontSize: 15.0),
              ),
            ),
            footerNotes: Text(
              """温馨提示：
1、每个自然月仅能修改一次
2、紧张使用违规信息，则将被永久封禁
3、用户资料需审核，审核通过后将会展示，请耐心等待""",
              style: TextStyle(
                fontWeight: FontWeight.w400,
                fontSize: 13,
                color: Color(0xFF999999),
              ),
            ),
            primaryButtonText: '确定',
            onPrimaryButtonPressed: () {
              print('点击确定');
              signContent.value = textController.text.toString();
              Navigator.of(context).pop();
            },
          ),
        );
      },
    );
  }

  // 切换性别
  void toggleGender(String selectedGender) {
    gender.value = selectedGender;
  }
}